package com.cinema.model;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 排片类
 * 
 * @author Cinema Management System
 * @version 1.0.0
 */
public class Schedule {
    
    /**
     * 排片ID
     */
    private String scheduleId;
    
    /**
     * 电影ID
     */
    private String movieId;
    
    /**
     * 放映厅ID
     */
    private String hallId;
    
    /**
     * 放映时间
     */
    private LocalDateTime showTime;
    
    /**
     * 票价
     */
    private BigDecimal price;
    
    /**
     * 排片状态
     */
    private ScheduleStatus status;
    
    /**
     * 默认构造函数
     */
    public Schedule() {
        this.status = ScheduleStatus.SCHEDULED;
    }
    
    /**
     * 构造函数
     * 
     * @param scheduleId 排片ID
     * @param movieId 电影ID
     * @param hallId 放映厅ID
     * @param showTime 放映时间
     * @param price 票价
     */
    public Schedule(String scheduleId, String movieId, String hallId, LocalDateTime showTime, BigDecimal price) {
        this();
        this.scheduleId = scheduleId;
        this.movieId = movieId;
        this.hallId = hallId;
        this.showTime = showTime;
        this.price = price;
    }
    
    /**
     * 检查是否可以修改排片
     * 
     * @return 是否可以修改
     */
    public boolean canModify() {
        return status != ScheduleStatus.SOLD && status != ScheduleStatus.COMPLETED;
    }
    
    /**
     * 检查是否可以删除排片
     * 
     * @return 是否可以删除
     */
    public boolean canDelete() {
        return status != ScheduleStatus.SOLD && status != ScheduleStatus.COMPLETED;
    }
    
    /**
     * 检查是否已过期
     * 
     * @return 是否已过期
     */
    public boolean isExpired() {
        return showTime.isBefore(LocalDateTime.now());
    }
    
    /**
     * 获取剩余时间（分钟）
     * 
     * @return 剩余时间
     */
    public long getRemainingMinutes() {
        if (isExpired()) {
            return 0;
        }
        return java.time.Duration.between(LocalDateTime.now(), showTime).toMinutes();
    }
    
    // Getter和Setter方法
    public String getScheduleId() {
        return scheduleId;
    }
    
    public void setScheduleId(String scheduleId) {
        this.scheduleId = scheduleId;
    }
    
    public String getMovieId() {
        return movieId;
    }
    
    public void setMovieId(String movieId) {
        this.movieId = movieId;
    }
    
    public String getHallId() {
        return hallId;
    }
    
    public void setHallId(String hallId) {
        this.hallId = hallId;
    }
    
    public LocalDateTime getShowTime() {
        return showTime;
    }
    
    public void setShowTime(LocalDateTime showTime) {
        this.showTime = showTime;
    }
    
    public BigDecimal getPrice() {
        return price;
    }
    
    public void setPrice(BigDecimal price) {
        if (price.compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("票价必须大于0");
        }
        this.price = price;
    }
    
    public ScheduleStatus getStatus() {
        return status;
    }
    
    public void setStatus(ScheduleStatus status) {
        this.status = status;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        Schedule schedule = (Schedule) obj;
        return Objects.equals(scheduleId, schedule.scheduleId);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(scheduleId);
    }
    
    @Override
    public String toString() {
        return "Schedule{" +
                "scheduleId='" + scheduleId + '\'' +
                ", movieId='" + movieId + '\'' +
                ", hallId='" + hallId + '\'' +
                ", showTime=" + showTime +
                ", price=" + price +
                ", status=" + status +
                '}';
    }
} 